package com.credithc.customers.dataservice.controller;

import com.credithc.customers.dataservice.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("api/data/yzt/v1/service/data")
public class OldDataController {
    @Autowired
    private OldDlrDataService oldDlrDataService;
    @Autowired
    private OldHydDataService oldHydDataService;
    @Autowired
    private OldHyrDataService oldHyrDataService;
    @Autowired
    private OldXhqbDataService oldXhqbDataService;
    @Autowired
    private OldJhzfDataService oldJhzfDataService;
    @Autowired
    private OldGdDataService oldGdDataService;
    @Autowired
    private OldXdDataService oldXdDataService;
    @Autowired
    private OldXtDataService oldXtDataService;
    @Autowired
    private OldHhrJKDataService oldHhrJKDataService;
    @Autowired
    private OldBDBataService oldBDBataService;
    @Autowired
    private OldFundDataService oldFundDataService;
    @Autowired
    private OldBXHXDataService oldBXHXDataService;

    @Autowired
    private OldCHDService oldCHDService;

    @Autowired
    private OldJWBXDataService oldJWBXDataService;
    @Autowired
    private OldHHRCFDataService oldHHRCFDataService;
    private static Integer hhrcf_p = 0;
    private static Integer hhrcf_o = 0;
    private static Integer hhrcf_a = 0;
    private static Integer jwbx_p = 0;
    private static Integer jwbx_o = 0;
    private static Integer chd_p = 0;
    private static  Integer chd_a = 0;
    private static Integer chd_o = 0;

    private static Integer bxhx_p = 0;
    private static  Integer bxhx_o = 0;
    private static Integer dlr = 0;
    private static Integer hyr = 0;
    private static Integer hyd = 0;
    private static Integer xhqb = 0;
    private static Integer jhzf = 0;
    private static Integer gd = 0;
    private static Integer xd = 0;
    private static Integer xt = 0;
    private static Integer hhrjk=0;
    private static Integer bdb_o = 0;
    private static Integer bdb_p = 0;
    private static Integer hyd_l = 0;
    private static Integer hyr_u = 0;
    private static Integer fund_o = 0;
    private static  Integer fund_p=0;

    @RequestMapping("/old")
    @CrossOrigin
    public String  getOldData(){
       /* ExecutorService e = Executors.newFixedThreadPool(9);
        e.submit(()->{ getHYRData(); });
        e.submit(()->{  getHydData(); });
        e.submit(()->{ getOldDLRData(); });
        e.submit(()->{ getXhqbData(); });
        e.submit(()->{ getJhzfData(); });
        e.submit(()->{ oldxD(); });
        e.submit(()->{ oldxt(); });
        e.submit(()->{  oldGD(); });
        e.submit(()->{ oldhhrjk(); });
        e.shutdown();*/
        return "ok";
    }
    @RequestMapping("dlr/old")
    @CrossOrigin
    public String  getOldDLRData(){
        if (dlr ==0) {
            dlr = 1;
            oldDlrDataService.oldProduct();
            oldDlrDataService.oldLend();
            oldDlrDataService.oldUser();
            oldDlrDataService.oldBankCard();
            dlr = 2;

        }
        return "ok";
    }
    @RequestMapping("/rest")
    @CrossOrigin
    public String rest(){
        dlr = 0;
        hyr = 0;
        hyd = 0;
        xhqb = 0;
        xd = 0;
        gd = 0;
        xt = 0;
        hhrjk = 0;
        jhzf = 0;
        bdb_o=0;
        bdb_p = 0;
        hyr_u=0;
        hyd_l=0;
        fund_o = 0;
        fund_p = 0;
        bxhx_o = 0;
        bxhx_p = 0;
        chd_a=0;
        chd_o = 0;
        chd_p = 0;
        jwbx_o= 0;
        jwbx_p = 0;
        hhrcf_a = 0;
        hhrcf_o = 0;
        hhrcf_p = 0;
        return "ok";
    }
    @RequestMapping("hyr/rest")
    @CrossOrigin
    public String restHyr(){
        hyr = 0;
        return "ok";
    }
    @RequestMapping("dlr/rest")
    @CrossOrigin
    public String restDlr(){
        dlr = 0;
        return "ok";
    }
    @RequestMapping("hyd/rest")
    @CrossOrigin
    public String restHyd(){
        hyd = 0;
        return "ok";
    }
    @RequestMapping("jhzf/rest")
    @CrossOrigin
    public String restJhzf(){
        jhzf = 0;
        return "ok";
    }
    @RequestMapping("xhqb/rest")
    @CrossOrigin
    public String restXhqb(){
        xhqb = 0;
        return "ok";
    }
    @RequestMapping("hyr/old")
    @CrossOrigin
    public String  getHYRData(){
        if (hyr == 0) {
            hyr = 1;
            oldHyrDataService.oldProduct();
            oldHyrDataService.oldLend();
            oldHyrDataService.oldBankCard();
            oldHyrDataService.oldUser(null);
            hyr = 2;
        }
        return "ok";
    }
    @RequestMapping("hyr/user/old")
    @CrossOrigin
    public String  getHYRUserData(Integer start){
        if (hyr_u == 0) {
            hyr_u = 1;
            oldHyrDataService.oldUser(start);
            hyr_u = 2;
        }
        return "ok";
    }
    @RequestMapping("hyd/order/old")
    @CrossOrigin
    public String getHydData(Integer start){
        if (hyd_l == 0){
            hyd_l = 1;
            oldHydDataService.oldOrder(start);
            hyd_l = 2;
        }
        return "ok";
    }
    @RequestMapping("hyd/bank/old")
    @CrossOrigin
    public String getHydbankData(Integer start){
        if (hyd == 0){
            hyd = 1;
            oldHydDataService.oldBank(start);
            hyd = 2;
        }
        return "ok";
    }

    @RequestMapping("xhqb/old")
    @CrossOrigin
    public String getXhqbData(){
        if (xhqb == 0){
            xhqb = 1;
            oldXhqbDataService.oldOrder();
            oldXhqbDataService.oldBank();
            xhqb = 2;
        }
        return "ok";
    }
    @RequestMapping("jhzf/old")
    @CrossOrigin
    public String getJhzfData(){
        if (jhzf == 0){
            jhzf = 1;
            oldJhzfDataService.oldAccount();
            jhzf = 2;
        }
        return "ok";
    }

    @RequestMapping("old/status")
    @CrossOrigin
    public Map<String, String> getAll(){
        Map<String,String> map = new HashMap<>();
        Map<Integer,String> map1 = new HashMap<>();
        map1.put(0,"未导入");
        map1.put(1,"已开始");
        map1.put(2,"已完成");
        map.put("dlr",map1.get(dlr));
        map.put("hyr",map1.get(hyr));
        map.put("hyd",map1.get(hyd));
        map.put("xhqb",map1.get(xhqb));
        map.put("jhzf",map1.get(jhzf));
        map.put("gd",map1.get(gd));
        map.put("xd",map1.get(xd));
        map.put("xt",map1.get(xt));
        map.put("hhrjk",map1.get(hhrjk));
        map.put("bdb_o",map1.get(bdb_o));
        map.put("bdb_p",map1.get(bdb_p));
        map.put("fund_o",map1.get(fund_o));
        map.put("fund_p",map1.get(fund_p));
        map.put("HYD_L",map1.get(hyd_l));
        map.put("HYR_U",map1.get(hyr_u));
        map.put("bxhx_p",map1.get(bxhx_p));
        map.put("bxhx_o",map1.get(bxhx_o));
        map.put("chd_a",map1.get(chd_a));
        map.put("chd_o",map1.get(chd_o));
        map.put("chd_p",map1.get(chd_p));

        map.put("jwbx_p",map1.get(jwbx_p));
        map.put("jwbx_o",map1.get(jwbx_o));
        map.put("hhrcf_a",map1.get(hhrcf_a));
        map.put("hhrcf_o",map1.get(hhrcf_o));
        map.put("hhrcf_p",map1.get(hhrcf_p));
        return map;
    }
    @RequestMapping("gd/old")
    @CrossOrigin
    public String oldGD(){
        if (gd == 0){
            gd = 1;

            oldGdDataService.oldData();

            gd = 2;
        }
        return "ok";
    }

    @RequestMapping("gd/rest")
    @CrossOrigin
    public String restgd(){
        gd = 0;
        return "ok";
    }

    @RequestMapping("xd/old")
    @CrossOrigin
    public String oldxD(){
        if (xd == 0){
            xd = 1;
            oldXdDataService.oldData();
            xd = 2;
        }
        return "ok";
    }

    @RequestMapping("xd/rest")
    @CrossOrigin
    public String restxd(){
        xd = 0;
        return "ok";
    }

    @RequestMapping("xt/old")
    @CrossOrigin
    public String oldxt(){
        if (xt == 0){
            xt = 1;
            oldXtDataService.oldData();
            xt = 2;
        }
        return "ok";
    }

    @RequestMapping("xt/rest")
    @CrossOrigin
    public String restxt(){
        xt = 0;
        return "ok";
    }
    @RequestMapping("hhrjk/old")
    @CrossOrigin
    public String oldhhrjk(){
        if (hhrjk == 0){
            hhrjk = 1;
            oldHhrJKDataService.oldAccount();
            oldHhrJKDataService.oldBank();
            hhrjk = 2;
        }
        return "ok";
    }

    @RequestMapping("hhrjk/rest")
    @CrossOrigin
    public String resthhrjk(){
        hhrjk = 0;
        return "ok";
    }

    @RequestMapping("bdb/product/old")
    @CrossOrigin
    public String oldbdb(Integer start){
        if (bdb_p == 0){
            bdb_p = 1;
           // oldBDBataService.oldOrder();
            oldBDBataService.oldProduct(start);
            bdb_p = 2;
        }
        return "ok";
    }
    @RequestMapping("bdb/order/old")
    @CrossOrigin
    public String oldorderbdb(Integer start){
        if (bdb_o == 0){
            bdb_o = 1;
            oldBDBataService.oldOrder(start);
            //oldBDBataService.oldProduct(start);
            bdb_o = 2;
        }
        return "ok";
    }
    @RequestMapping("fund/product/old")
    @CrossOrigin
    public String fund(Integer start){
        if (fund_p == 0){
            fund_p = 1;
            oldFundDataService.oldProduct(start);
            fund_p = 2;
        }
        return "ok";
    }
    @RequestMapping("fund/order/old")
    @CrossOrigin
    public String fundOrder(Integer start){
        if (fund_o == 0){
            fund_o = 1;
            oldFundDataService.oldData(start);
            fund_o = 2;
        }
        return "ok";
    }

    @RequestMapping("fund/rest")
    @CrossOrigin
    public String restfund(){
        fund_o = 0;
        fund_p = 0;
        return "ok";
    }
    @RequestMapping("bdb/rest")
    @CrossOrigin
    public String restbdb(){
        bdb_o = 0;
        bdb_p = 0;
        return "ok";
    }
    @RequestMapping("bxhx/product/old")
    @CrossOrigin
    public String HXBX(Integer start){
        if (bxhx_p == 0){
            bxhx_p = 1;
            oldBXHXDataService.product(start);
            bxhx_p = 2;
        }
        return "ok";
    }
    @RequestMapping("bxhx/order/old")
    @CrossOrigin
    public String hxbxOrder(Integer start){
        if (bxhx_o == 0){
            bxhx_o = 1;
            oldBXHXDataService.data(start);
            bxhx_o = 2;
        }
        return "ok";
    }

    @RequestMapping("bxhx/rest")
    @CrossOrigin
    public String restbxhx(){
        bxhx_o = 0;
        bxhx_p = 0;
        return "ok";
    }

    @RequestMapping("chd/order/old")
    @CrossOrigin
    public String oldchd_o(Integer start){
        if (chd_o == 0){
            chd_o = 1;
            oldCHDService.oldorder(start);
            chd_o = 2;
        }
        return "ok";
    }
    @RequestMapping("chd/product/old")
    @CrossOrigin
    public String oldchd_p(Integer start){
        if (chd_p == 0){
            chd_p = 1;
            // oldBDBataService.oldOrder();
            oldCHDService.oldproduct(start);
            chd_p = 2;
        }
        return "ok";
    }
    @RequestMapping("chd/account/old")
    @CrossOrigin
    public String oldchd_a(Integer start){
        if (chd_a == 0){
            chd_a = 1;
            // oldBDBataService.oldOrder();
            oldCHDService.oldaccount(start);
            chd_a = 2;
        }
        return "ok";
    }

    @RequestMapping("chd/rest")
    @CrossOrigin
    public String restchd(){
        chd_o = 0;
        chd_a = 0;
        chd_p = 0;
        return "ok";
    }

    @RequestMapping("jwbx/product/old")
    @CrossOrigin
    public String oldjwbx_p(Integer start){
        if (jwbx_p == 0){
            jwbx_p = 1;
            // oldBDBataService.oldOrder();
            oldJWBXDataService.oldProduct(start);
            jwbx_p = 2;
        }
        return "ok";
    }
    @RequestMapping("jwbx/order/old")
    @CrossOrigin
    public String oldjwbx_o(Integer start){

        if (jwbx_o == 0){
            jwbx_o = 1;
            // oldBDBataService.oldOrder();
            oldJWBXDataService.oldOrder(start);
            jwbx_o = 2;
        }
        return "ok";
    }

    @RequestMapping("jwbx/rest")
    @CrossOrigin
    public String restjwbx(){
        jwbx_o = 0;
        jwbx_p = 0;;
        return "ok";
    }

    @RequestMapping("hhrcf/account/old")
    @CrossOrigin
    public String oldhhr_a(Integer start){

        if (hhrcf_a == 0){
            hhrcf_a = 1;
            // oldBDBataService.oldOrder();
            oldHHRCFDataService.account(start);
            //oldHHRCFDataService.oldData();
            hhrcf_a = 2;
        }
        return "ok";
    }

    @RequestMapping("hhrcf/order/old")
    @CrossOrigin
    public String oldhhrcf_o(Integer start){

        if (hhrcf_o == 0){
            hhrcf_o = 1;
            // oldBDBataService.oldOrder();
            oldHHRCFDataService.order(start);
            hhrcf_o = 2;
        }
        return "ok";
    }

    @RequestMapping("hhrcf/product/old")
    @CrossOrigin
    public String oldhhrcf_p(Integer start){

        if (hhrcf_p == 0){
            hhrcf_p = 1;
            // oldBDBataService.oldOrder();
            oldHHRCFDataService.product(start);
            hhrcf_p = 2;
        }
        return "ok";
    }
    @RequestMapping("hhrcf/rest")
    @CrossOrigin
    public String resthhrcf(){
        hhrcf_a = 0;
        hhrcf_p = 0;
        hhrcf_o = 0;
        return "ok";
    }

}
